﻿package mortal.game.view.daily.render
{
    import Message.Client.*;
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.common.tools.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.daily.*;

    public class NewDailyCellRenderer2 extends GCellRenderer
    {
        protected var _bg:ScaleBitmap;
        protected var _iconBg:ScaleBitmap;
        protected var _icon:GImageBitmap;
        protected var _rwBg:GBitmap;
        protected var _commonName:GImageBitmap;
        protected var _rwType:GBitmap;
        protected var _plan:GTextFiled;
        protected var _lv:BitmapNumberText;
        protected var _operBtn:GButton;
        protected var _name:GTextFiled;
        protected var _btnFlyBoot:GLoadedButton;
        protected var _findLinkBtn:GButton;
        protected var _state:GBitmap;
        protected var _lvDes:GBitmap;
        protected var _timeTip:GBitmap;
        protected var _timeTip2:GBitmap;
        private var _selectFilter:ScaleBitmap;
        private var _isResCompl:Boolean;

        public function NewDailyCellRenderer2()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._selectFilter = UIFactory.bg(-1, -1, 552, 59, this, ImagesConst.selectFilter);
            this._bg = UIFactory.bg(0, 0, 550, 57, this, ImagesConst.PanelBg);
            LoaderHelp.addResCallBack(ResFileConst.daily, this.onResCompl);
            return;
        }// end function

        private function onResCompl() : void
        {
            this._isResCompl = true;
            this._bg = UIFactory.bg(-1, 0, 550, 57, this, ImagesConst.PanelBg);
            this._iconBg = UIFactory.bg(6, 5, 49, 48, this, ImagesConst.ShopItemBg);
            this._icon = UIFactory.gImageBitmap("daily_single_defense_copy.jpg", 9, 8, this);
            this._rwBg = UIFactory.gBitmap(ImagesConst.DailyRenderBossBg1, 58, 33, this);
            this._commonName = UIFactory.gImageBitmap("name_treasure.png", 74, 16, this);
            this._rwType = UIFactory.gBitmap(ImagesConst.DailyTxtRd8, 144, 15, this);
            this._plan = UIFactory.gTextField("", 227, 28, 190, 20, this, GlobalStyle.textFormatHuang2.setSize(13).center().setBold(true));
            this._lv = UIFactory.bitmapNumberText(442, 23, "DailyActiveNum.png", 11, 16, -2, this, 9, 0);
            this._lv.text = "66";
            this._operBtn = UIFactory.gButton("" + Language.getString(71038), 471, 20, 62, 23, this);
            this._name = UIFactory.gTextField("10/20", 203, 15, 50, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._btnFlyBoot = UIFactory.gLoadedButton(ImagesConst.MapBtnFlyBoot_upSkin, 516, 22, 16, 18, this);
            this._btnFlyBoot.label = "";
            this._findLinkBtn = UIFactory.gButton("" + Language.getString(71039), 472, 15, 50, 30, this, "GreenLinkButton");
            this._state = UIFactory.gBitmap(ImagesConst.DailyTxt9, 324, 13, this);
            this._lvDes = UIFactory.gBitmap(ImagesConst.DailyTxt11, 420, 23, this);
            this._timeTip = UIFactory.gBitmap(ImagesConst.DailyTxt19, 275, 10, this);
            this._timeTip2 = UIFactory.gBitmap(ImagesConst.DailyLevelOpen, 470, 22, this);
            this._timeTip2.visible = false;
            var _loc_1:Number = 0.7;
            this._icon.scaleY = 0.7;
            this._icon.scaleX = _loc_1;
            this._operBtn.configEventListener(MouseEvent.CLICK, this.onClickOperBtnHandler);
            this._findLinkBtn.configEventListener(MouseEvent.CLICK, this.onClickOperBtnHandler);
            this._btnFlyBoot.configEventListener(MouseEvent.CLICK, this.onClickBtnFlyBoot);
            this.setData();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._isResCompl = false;
            LoaderHelp.removeResEvent(ResFileConst.daily, this.onResCompl);
            this._bg = null;
            this._iconBg = null;
            this._icon = null;
            this._rwBg = null;
            this._commonName = null;
            this._rwType = null;
            this._plan = null;
            this._lv = null;
            this._operBtn = null;
            this._name = null;
            this._btnFlyBoot = null;
            this._findLinkBtn = null;
            this._state = null;
            this._lvDes = null;
            this._timeTip = null;
            this._timeTip2 = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onClickOperBtnHandler(event:MouseEvent) : void
        {
            DailyUtil.oper(this.itemData);
            return;
        }// end function

        private function onClickBtnFlyBoot(event:MouseEvent) : void
        {
            DailyUtil.oper(this.itemData, true);
            return;
        }// end function

        private function get itemData() : TDailyViewConfig
        {
            return _data as TDailyViewConfig;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this.setData();
            return;
        }// end function

        private function setData() : void
        {
            if (_data && this._isResCompl)
            {
                this._icon.imgUrl = this.itemData.icon + ".jpg";
                this._lv.text = this.itemData.minLevel.toString();
                this._btnFlyBoot.visible = false;
                this._commonName.imgUrl = this.itemData.namePic + ".png";
                this.setBtnLabel();
                this.setPlanTxt();
                this.setStar();
                this._timeTip2.visible = false;
                this.judgeTimeTipRule();
            }
            return;
        }// end function

        private function judgeTimeTipRule() : void
        {
            if (_data == null || this._isResCompl == false)
            {
                return;
            }
            var _loc_1:* = Cache.instance.daily.todayNotOpenActives;
            var _loc_2:* = _loc_1.indexOf(this.itemData.id) == -1;
            if (!_loc_2)
            {
                this.showTimeTip("over");
                this._plan.text = "" + Language.getString(71040);
                return;
            }
            if (this.itemData.hasOwnProperty("openDays"))
            {
                this.judgeOpenDays();
            }
            else if (this.itemData.hasOwnProperty("openWeekDay"))
            {
                this.judgeWeekDay();
            }
            else
            {
                this.judgeCommon();
            }
            this.updateRightTip2();
            this.checkTime();
            return;
        }// end function

        private function judgeOpenDays() : void
        {
            this.judgeCommon();
            return;
        }// end function

        private function judgeWeekDay() : void
        {
            if (DailyUtil.getIsInDay(this.itemData.id))
            {
                this.judgeCommon();
            }
            else
            {
                this.showTimeTip("over");
            }
            return;
        }// end function

        private function checkTime() : void
        {
            if (this.itemData.isDisplay == 0)
            {
                this.showTipPos(false, true);
            }
            return;
        }// end function

        private function isLevelEnougth() : Boolean
        {
            return Cache.instance.role.entityInfo.level >= this.itemData.minLevel;
        }// end function

        private function judgeCommon(param1:Function = null) : void
        {
            var _loc_2:Array = null;
            var _loc_3:int = 0;
            if (DailyUtil.isInActiveTime(this.itemData))
            {
                this.filters = null;
                if (DailyUtil.isOpenNow(this.itemData))
                {
                    this.showTimeTip("now");
                }
                else
                {
                    _loc_2 = DailyUtil.curArr;
                    _loc_3 = DailyUtil.getBeginIndex();
                    if (_loc_2 && _loc_3 == _loc_2.indexOf(_data))
                    {
                        this.showTimeTip("soon");
                    }
                    else
                    {
                        this.showTipPos(false, true);
                    }
                    this._rwBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyRenderBossBg1);
                }
            }
            else
            {
                this.showTimeTip("over");
                if (param1 != null)
                {
                    this.param1();
                }
            }
            return;
        }// end function

        private function judgeLevel(param1:String) : void
        {
            if (this.isLevelEnougth())
            {
                this.showTimeTip(param1);
            }
            return;
        }// end function

        private function updateRightTip2() : void
        {
            if (this.itemData.hasOwnProperty("openDays"))
            {
                if (this.isInOpenServerDay(this.itemData) == false)
                {
                    this._timeTip2.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyOpenNextDay);
                    this.visibleRightTip(true);
                    this.showTipPos(false, true);
                    return;
                }
            }
            if (this.isLevelEnougth() == false)
            {
                this._timeTip2.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyLevelOpen);
                this.visibleRightTip(true);
            }
            else
            {
                this.visibleRightTip(false);
            }
            return;
        }// end function

        private function showTimeTip(param1:String) : void
        {
            this.showTipPos(true, false);
            switch(param1)
            {
                case "now":
                {
                    this._timeTip.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyTxt19);
                    this._rwBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyRenderBossBg1);
                    break;
                }
                case "over":
                {
                    this._timeTip.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyTxt21);
                    this.filters = [FilterConst.colorFilter2];
                    break;
                }
                case "soon":
                {
                    this._timeTip.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyTxt20);
                    this.filters = null;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function visibleRightTip(param1:Boolean) : void
        {
            if (param1)
            {
                this._timeTip2.visible = true;
                this._operBtn.visible = false;
                this._btnFlyBoot.visible = false;
                this._findLinkBtn.visible = false;
            }
            else
            {
                this.setBtnLabel();
                this._timeTip2.visible = false;
            }
            return;
        }// end function

        private function isInOpenServerDay(param1:TDailyViewConfig) : Boolean
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (this.itemData.hasOwnProperty("openDays"))
            {
                _loc_2 = int(this.itemData["openDays"]);
                _loc_3 = ClockManager.instance.serverOpenDateNum;
                if (_loc_3 >= _loc_2)
                {
                    return true;
                }
            }
            return false;
        }// end function

        private function showTipPos(param1:Boolean, param2:Boolean) : void
        {
            this._timeTip.visible = param1;
            if (param2)
            {
                this._plan.y = 18;
            }
            else
            {
                this._plan.y = 28;
            }
            return;
        }// end function

        private function setBtnLabel() : void
        {
            if (this.itemData.operType == EDailyOperType._EDailyOperTypeModule)
            {
                this._operBtn.label = Language.getString(70404);
                this._operBtn.visible = true;
                var _loc_1:Boolean = false;
                this._btnFlyBoot.visible = false;
                this._findLinkBtn.visible = _loc_1;
            }
            else if (this.itemData.operType == EDailyOperType._EDailyOperTypePathing)
            {
                this._operBtn.label = Language.getString(70403);
                this._operBtn.visible = false;
                var _loc_1:Boolean = true;
                this._btnFlyBoot.visible = true;
                this._findLinkBtn.visible = _loc_1;
            }
            if (this.itemData.expStar > 0 && Cache.instance.task.needLevelToCompleteTask != null && Cache.instance.daily.hasTime(this.itemData))
            {
                this._operBtn.filters = [FilterConst.guideFilter];
            }
            else
            {
                this._operBtn.filters = [];
            }
            return;
        }// end function

        private function setPlanTxt() : void
        {
            var _loc_2:String = null;
            var _loc_3:String = null;
            var _loc_4:Array = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:String = null;
            var _loc_1:* = Cache.instance.daily;
            this._name.text = "";
            this._plan.textColor = GlobalStyle.colorLvUint;
            if (int(this.itemData.times) > 0)
            {
                if (int(_loc_1.data.times[this.itemData.type]) >= int(this.itemData.times))
                {
                    this._state.visible = true;
                    this._plan.textColor = GlobalStyle.colorHuang2Uint;
                    this._plan.text = "" + Language.getString(71036);
                    this._name.text = this._name.text + (int(this.itemData.times) + "/" + this.itemData.times);
                }
                else
                {
                    this._state.visible = false;
                    this._plan.text = "" + Language.getString(71036);
                    this._name.text = this._name.text + (int(_loc_1.data.times[this.itemData.type]) + "/" + this.itemData.times);
                }
            }
            else if (this.itemData.normalOpenDt)
            {
                this.setBtnFilters(this.itemData.normalOpenDt);
                _loc_2 = DailyUtil.getTimeStr(this.itemData.normalOpenDt);
                if (this.itemData.openWeekDay)
                {
                    _loc_3 = "";
                    _loc_4 = this.itemData.openWeekDay.split("#");
                    _loc_5 = _loc_4.length;
                    _loc_6 = 0;
                    while (_loc_6 < _loc_5)
                    {
                        
                        _loc_3 = _loc_3 + GameDefConfig.instance.getChineseNum(int(_loc_4[_loc_6]));
                        _loc_6++;
                    }
                    this._plan.text = Language.getStringByParam(70407, _loc_3 + _loc_2);
                }
                else
                {
                    _loc_7 = this.itemData.group == EDailyType._EDailyTypeBoss && this.itemData.extendStr ? (this.itemData.extendStr) : ("");
                    this._plan.text = Language.getStringByParam(70408, _loc_2) + _loc_7;
                }
                this._state.visible = false;
                this._name.text = this._name.text + ("" + Language.getString(71037));
            }
            else
            {
                this._plan.text = "" + Language.getString(71036);
                this._name.text = this._name.text + ("" + Language.getString(71037));
                this._state.visible = false;
            }
            var _loc_8:* = !this._state.visible;
            this._plan.visible = !this._state.visible;
            this._timeTip.visible = _loc_8;
            return;
        }// end function

        private function setBtnFilters(param1:String) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Array = null;
            var _loc_4:Boolean = false;
            var _loc_5:Date = null;
            var _loc_6:Date = null;
            var _loc_7:Date = null;
            var _loc_8:Date = null;
            var _loc_9:Date = null;
            if (param1.indexOf("#") != -1)
            {
                _loc_3 = param1.split("#");
                _loc_5 = DateUtil.getDateByHourAndMin(String(_loc_3[0]));
                _loc_6 = DateUtil.getDateByHourAndMin(String(_loc_3[1]));
                _loc_4 = DateUtil.isInDate(_loc_5, _loc_6);
                _loc_2 = _loc_5.day;
            }
            else if (param1.indexOf("&") != -1)
            {
                _loc_3 = param1.split("&");
                _loc_7 = DateUtil.getDateByHourAndMin(String(_loc_3[0]));
                _loc_4 = DateUtil.isInDate(new Date(_loc_7.time - 5 * 60 * 1000), new Date(_loc_7.time + 5 * 60 * 1000));
                if (_loc_4 == false)
                {
                    _loc_8 = DateUtil.getDateByHourAndMin(String(_loc_3[1]));
                    _loc_4 = DateUtil.isInDate(new Date(_loc_8.time - 5 * 60 * 1000), new Date(_loc_8.time + 5 * 60 * 1000));
                }
                _loc_2 = _loc_7.day;
            }
            else
            {
                _loc_9 = DateUtil.getDateByHourAndMin(param1);
                _loc_4 = DateUtil.isInDate(new Date(_loc_9.time - 5 * 60 * 1000), new Date(_loc_9.time + 5 * 60 * 1000));
                _loc_2 = _loc_9.day;
            }
            if (this.itemData.openWeekDay)
            {
                _loc_4 = _loc_4 && this.itemData.openWeekDay.indexOf(_loc_2.toString()) != -1;
            }
            if (Cache.instance.role.entityInfo.level >= this.itemData.minLevel && _loc_4)
            {
            }
            return;
        }// end function

        private function setStar() : void
        {
            this._rwType.bitmapData = GlobalClass.getBitmapData("DailyTxtRd" + this.itemData.extendStr);
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            super.selected = param1;
            this._selectFilter.visible = param1;
            return;
        }// end function

    }
}
